__author__ = 'Administrator'
#__author__ = 'Administrator'
#coding=utf-8

from Application import application,request,jsonify
from selenium import webdriver
from PIL import Image
@application.route('/generate', methods=['POST'])
def generate():
    url = request.form['url']
    fileUrl = request.form['fileUrl']
    driver = webdriver.PhantomJS()
    driver.set_page_load_timeout(300)
    driver.set_window_size(600,480)
    driver.get(url)
    print driver.title
    imgelement = driver.find_element_by_id('content')
    location = imgelement.location
    size = imgelement.size
    driver.save_screenshot(fileUrl)
    im = Image.open(fileUrl)
    left = location['x']
    top = int(location['y'])
    right = left + size['width']
    bottom = int(location['y'] + size['height'])
    im = im.crop((left,top,right,bottom))
    im.save(fileUrl)
    return jsonify({'info':'ok','status':1})

@application.route('/', methods=['GET', 'POST'])
def index():
    return 'index'